package com.resys.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.resys.entity.enums.PageSize;
import com.resys.entity.query.RoomdeviceQuery;
import com.resys.entity.po.Roomdevice;
import com.resys.entity.vo.PaginationResultVO;
import com.resys.entity.query.SimplePage;
import com.resys.mappers.RoomdeviceMapper;
import com.resys.service.RoomdeviceService;
import com.resys.utils.StringTools;


/**
 *  业务接口实现
 */
@Service("roomdeviceService")
public class RoomdeviceServiceImpl implements RoomdeviceService {

	@Resource
	private RoomdeviceMapper<Roomdevice, RoomdeviceQuery> roomdeviceMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<Roomdevice> findListByParam(RoomdeviceQuery param) {
		return this.roomdeviceMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(RoomdeviceQuery param) {
		return this.roomdeviceMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<Roomdevice> findListByPage(RoomdeviceQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<Roomdevice> list = this.findListByParam(param);
		PaginationResultVO<Roomdevice> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(Roomdevice bean) {
		return this.roomdeviceMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<Roomdevice> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.roomdeviceMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<Roomdevice> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.roomdeviceMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(Roomdevice bean, RoomdeviceQuery param) {
		StringTools.checkParam(param);
		return this.roomdeviceMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(RoomdeviceQuery param) {
		StringTools.checkParam(param);
		return this.roomdeviceMapper.deleteByParam(param);
	}

	/**
	 * 根据RoomIdAndDeviceId获取对象
	 */
	@Override
	public Roomdevice getRoomdeviceByRoomIdAndDeviceId(Integer roomId, Integer deviceId) {
		return this.roomdeviceMapper.selectByRoomIdAndDeviceId(roomId, deviceId);
	}

	/**
	 * 根据RoomIdAndDeviceId修改
	 */
	@Override
	public Integer updateRoomdeviceByRoomIdAndDeviceId(Roomdevice bean, Integer roomId, Integer deviceId) {
		return this.roomdeviceMapper.updateByRoomIdAndDeviceId(bean, roomId, deviceId);
	}

	/**
	 * 根据RoomIdAndDeviceId删除
	 */
	@Override
	public Integer deleteRoomdeviceByRoomIdAndDeviceId(Integer roomId, Integer deviceId) {
		return this.roomdeviceMapper.deleteByRoomIdAndDeviceId(roomId, deviceId);
	}
}